package com.bilin.coin.list;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bilin.coin.R;
import com.bilin.coin.bean.DiaRecordBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.utils.DensityUtils;
import com.bilin.coin.utils.GsonUtil;
import com.bilin.coin.utils.MoneyUtils;
import com.bilin.coin.utils.SpacesItemDecoration;
import com.bilin.coin.widget.AbsPullToRefreshRecycleView;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class DigRecordList extends AbsPullToRefreshRecycleView<DiaRecordBean.RecordsBean> {


    public DigRecordList(BaseAppCompatActivity activity) {
        super(activity, true, false, true);
    }

    @Override
    public int fillPageSize() {
        return 15;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public List parseListDataAndFillTotal(String dataJson) {
        DiaRecordBean digToolsBean = GsonUtil.GsonToBean(dataJson, DiaRecordBean.class);
        totalCount = digToolsBean.getTotal();
        return digToolsBean.getRecords();
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage", page + "");
        params.put("pageSize", pageSize + "");
        return params;
    }

    @Override
    protected RecyclerView.LayoutManager fillLayoutManger() {
        LinearLayoutManager manager = new LinearLayoutManager(activity);
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.addItemDecoration(new SpacesItemDecoration(1, DensityUtils.dp2px(activity, 10), 0x1888));
        return manager;
    }

    @Override
    public String fillUrl() {
        return "/api/award-log/list";
    }

    @Override
    protected void convertItem(BaseViewHolder helper, DiaRecordBean.RecordsBean item) {
        helper.setText(R.id.tv_static, ""+ MoneyUtils.decimal2ByUp(new BigDecimal(item.getStaticAward())));
        helper.setText(R.id.tv_recommend, ""+ MoneyUtils.decimal2ByUp(new BigDecimal(item.getDynamicAward())));
        helper.setText(R.id.tv_com, ""+ MoneyUtils.decimal2ByUp(new BigDecimal(item.getUnionAward())));
        helper.setText(R.id.tv_same_level, ""+ MoneyUtils.decimal2ByUp(new BigDecimal(item.getSameLevelAward())));
        helper.setText(R.id.tv_global, ""+ MoneyUtils.decimal2ByUp(new BigDecimal(item.getGlobalAward())));
        helper.setText(R.id.tv_composite, ""+ MoneyUtils.decimal2ByUp(new BigDecimal(item.getTotalAward())));
        helper.setText(R.id.tv_time, ""+item.getUpdateTime());
    }

    @Override
    protected int fillAnimationType() {
        return BaseQuickAdapter.ALPHAIN;
    }

    @Override
    protected int fillItemLayout() {
        return R.layout.item_dig_record;
    }
}
